﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core.IMessage;
using HslCommunication.Enthernet.Redis;
using HslCommunication.LogNet;
using HslCommunication.MQTT;
using HslCommunication.WebSocket;

namespace HslCommunication.Core.Net
{
	/// <summary>
	/// 本系统所有网络类的基类，该类为抽象类，无法进行实例化，如果想使用里面的方法来实现自定义的网络通信，请通过继承使用。<br />
	/// The base class of all network classes in this system. This class is an abstract class and cannot be instantiated. 
	/// If you want to use the methods inside to implement custom network communication, please use it through inheritance.
	/// </summary>
	/// <remarks>
	/// 本类提供了丰富的底层数据的收发支持，包含<see cref="T:HslCommunication.Core.IMessage.INetMessage" />消息的接收，<c>MQTT</c>以及<c>Redis</c>,<c>websocket</c>协议的实现
	/// </remarks>
	// Token: 0x02000137 RID: 311
	public abstract class NetworkBase
	{
		/// <summary>
		/// 实例化一个NetworkBase对象，令牌的默认值为空，都是0x00<br />
		/// Instantiate a NetworkBase object, the default value of the token is empty, both are 0x00
		/// </summary>
		// Token: 0x060019E7 RID: 6631 RVA: 0x0008154C File Offset: 0x0007F74C
		public NetworkBase()
		{
			this.Token = Guid.Empty;
			Authorization.oasjodaiwfsodopsdjpasjpf();
		}

		/// <summary>
		/// 组件的日志工具，支持日志记录，只要实例化后，当前网络的基本信息，就以<see cref="F:HslCommunication.LogNet.HslMessageDegree.DEBUG" />等级进行输出<br />
		/// The component's logging tool supports logging. As long as the instantiation of the basic network information, the output will be output at <see cref="F:HslCommunication.LogNet.HslMessageDegree.DEBUG" />
		/// </summary>
		/// <remarks>
		/// 只要实例化即可以记录日志，实例化的对象需要实现接口 <see cref="T:HslCommunication.LogNet.ILogNet" /> ，本组件提供了三个日志记录类，你可以实现基于 <see cref="T:HslCommunication.LogNet.ILogNet" />  的对象。</remarks>
		/// <example>
		/// 如下的实例化适用于所有的Network及其派生类，以下举两个例子，三菱的设备类及服务器类
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="LogNetExample1" title="LogNet示例" />
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="LogNetExample2" title="LogNet示例" />
		/// </example>
		// Token: 0x17000562 RID: 1378
		// (get) Token: 0x060019E8 RID: 6632 RVA: 0x00081581 File Offset: 0x0007F781
		// (set) Token: 0x060019E9 RID: 6633 RVA: 0x00081589 File Offset: 0x0007F789
		public ILogNet LogNet { get; set; }

		/// <summary>
		/// 网络类的身份令牌，在hsl协议的模式下会有效，在和设备进行通信的时候是无效的<br />
		/// Network-type identity tokens will be valid in the hsl protocol mode and will not be valid when communicating with the device
		/// </summary>
		/// <remarks>
		/// 适用于Hsl协议相关的网络通信类，不适用于设备交互类。
		/// </remarks>
		/// <example>
		/// 此处以 <see cref="T:HslCommunication.Enthernet.NetSimplifyServer" /> 服务器类及 <see cref="T:HslCommunication.Enthernet.NetSimplifyClient" /> 客户端类的令牌设置举例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="TokenClientExample" title="Client示例" />
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="TokenServerExample" title="Server示例" />
		/// </example>
		// Token: 0x17000563 RID: 1379
		// (get) Token: 0x060019EA RID: 6634 RVA: 0x00081592 File Offset: 0x0007F792
		// (set) Token: 0x060019EB RID: 6635 RVA: 0x0008159A File Offset: 0x0007F79A
		public Guid Token { get; set; }

		/// <summary>
		/// 接收固定长度的字节数组，允许指定超时时间，默认为60秒，当length大于0时，接收固定长度的数据内容，当length小于0时，接收不大于2048长度的随机数据信息<br />
		/// Receiving a fixed-length byte array, allowing a specified timeout time. The default is 60 seconds. When length is greater than 0, 
		/// fixed-length data content is received. When length is less than 0, random data information of a length not greater than 2048 is received.
		/// </summary>
		/// <param name="socket">网络通讯的套接字<br />Network communication socket</param>
		/// <param name="length">准备接收的数据长度，当length大于0时，接收固定长度的数据内容，当length小于0时，接收不大于1024长度的随机数据信息</param>
		/// <param name="timeOut">单位：毫秒，超时时间，默认为60秒，如果设置小于0，则不检查超时时间</param>
		/// <param name="reportProgress">当前接收数据的进度报告，有些协议支持传输非常大的数据内容，可以给与进度提示的功能</param>
		/// <returns>包含了字节数据的结果类</returns>
		// Token: 0x060019EC RID: 6636 RVA: 0x000815A4 File Offset: 0x0007F7A4
		protected OperateResult<byte[]> Receive(Socket socket, int length, int timeOut = 60000, Action<long, long> reportProgress = null)
		{
			bool flag = length == 0;
			OperateResult<byte[]> result;
			if (flag)
			{
				//如果指定接收长度为0，直接返回
				result = OperateResult.CreateSuccessResult<byte[]>(new byte[0]);
			}
			else
			{
				bool flag2 = !Authorization.nzugaydgwadawdibbas();
				if (flag2)
				{
					result = new OperateResult<byte[]>(StringResources.Language.AuthorizationFailed);
				}
				else
				{
					try
					{
						socket.ReceiveTimeout = timeOut;
						bool flag3 = length > 0;
						//如果长度设置为负数，则接收缓冲区内所有字节
						if (flag3)
						{
							byte[] value = NetSupport.ReadBytesFromSocket(socket, length, reportProgress);
							result = OperateResult.CreateSuccessResult<byte[]>(value);
						}
						else
						{
							byte[] array = new byte[2048];
							int num = socket.Receive(array);
							bool flag4 = num == 0;
							if (flag4)
							{
								throw new RemoteCloseException();
							}
							result = OperateResult.CreateSuccessResult<byte[]>(SoftBasic.ArraySelectBegin<byte>(array, num));
						}
					}
					catch (RemoteCloseException)
					{
						if (socket != null)
						{
							socket.Close();
						}
						bool flag5 = this.connectErrorCount < 1000000000;
						if (flag5)
						{
							this.connectErrorCount++;
						}
						result = new OperateResult<byte[]>(-this.connectErrorCount, "Socket Exception -> " + StringResources.Language.RemoteClosedConnection);
					}
					catch (Exception ex)
					{
						if (socket != null)
						{
							socket.Close();
						}
						bool flag6 = this.connectErrorCount < 1000000000;
						if (flag6)
						{
							this.connectErrorCount++;
						}
						result = new OperateResult<byte[]>(-this.connectErrorCount, "Socket Exception -> " + ex.Message);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 接收一行命令数据，需要自己指定这个结束符，默认超时时间为60秒，也即是60000，单位是毫秒<br />
		/// To receive a line of command data, you need to specify the terminator yourself. The default timeout is 60 seconds, which is 60,000, in milliseconds.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="endCode">结束符信息</param>
		/// <param name="timeout">超时时间，默认为60000，单位为毫秒，也就是60秒</param>
		/// <returns>带有结果对象的数据信息</returns>
		// Token: 0x060019ED RID: 6637 RVA: 0x00081714 File Offset: 0x0007F914
		protected OperateResult<byte[]> ReceiveCommandLineFromSocket(Socket socket, byte endCode, int timeout = 2147483647)
		{
			List<byte> list = new List<byte>();
			OperateResult<byte[]> result;
			try
			{
				DateTime now = DateTime.Now;
				bool flag = false;
				while ((DateTime.Now - now).TotalMilliseconds < (double)timeout)
				{
					//检查socket的连接状态
					bool flag2 = socket.Poll(timeout, SelectMode.SelectRead);
					if (flag2)
					{
						//按字节递进读取
						OperateResult<byte[]> operateResult = this.Receive(socket, 1, 60000, null);
						bool flag3 = !operateResult.IsSuccess;
						if (flag3)
						{
							return operateResult;
						}
						list.AddRange(operateResult.Content);
						//检查是否接收到结束符
						bool flag4 = operateResult.Content[0] == endCode;
						if (flag4)
						{
							flag = true;
							break;
						}
					}
				}
				bool flag5 = !flag;
				if (flag5)
				{
					//没有接收到结束符，返回失败结果
					result = new OperateResult<byte[]>(StringResources.Language.ReceiveDataTimeout);
				}
				else
				{
					//接收到结束符，返回接收到的字节数组
					result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
				}
			}
			catch (Exception ex)
			{
				if (socket != null)
				{
					socket.Close();
				}
				result = new OperateResult<byte[]>(ex.Message);
			}
			return result;
		}

		/// <summary>
		/// 接收一行命令数据，需要自己指定这个结束符，默认超时时间为60秒，也即是60000，单位是毫秒<br />
		/// To receive a line of command data, you need to specify the terminator yourself. The default timeout is 60 seconds, which is 60,000, in milliseconds.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="endCode1">结束符1信息</param>
		/// <param name="endCode2">结束符2信息</param>
		/// /// <param name="timeout">超时时间，默认无穷大，单位毫秒</param>
		/// <returns>带有结果对象的数据信息</returns>
		// Token: 0x060019EE RID: 6638 RVA: 0x0008180C File Offset: 0x0007FA0C
		protected OperateResult<byte[]> ReceiveCommandLineFromSocket(Socket socket, byte endCode1, byte endCode2, int timeout = 60000)
		{
			List<byte> list = new List<byte>();
			OperateResult<byte[]> result;
			try
			{
				DateTime now = DateTime.Now;
				bool flag = false;
				while ((DateTime.Now - now).TotalMilliseconds < (double)timeout)
				{
					bool flag2 = socket.Poll(timeout, SelectMode.SelectRead);
					if (flag2)
					{
						OperateResult<byte[]> operateResult = this.Receive(socket, 1, 60000, null);
						bool flag3 = !operateResult.IsSuccess;
						if (flag3)
						{
							return operateResult;
						}
						list.AddRange(operateResult.Content);
						bool flag4 = operateResult.Content[0] == endCode2;
						if (flag4)
						{
							bool flag5 = list.Count > 1 && list[list.Count - 2] == endCode1;
							if (flag5)
							{
								flag = true;
								break;
							}
						}
					}
				}
				bool flag6 = !flag;
				if (flag6)
				{
					result = new OperateResult<byte[]>(StringResources.Language.ReceiveDataTimeout);
				}
				else
				{
					result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
				}
			}
			catch (Exception ex)
			{
				if (socket != null)
				{
					socket.Close();
				}
				result = new OperateResult<byte[]>(ex.Message);
			}
			return result;
		}

		/// <summary>
		/// 接收一条完整的 <seealso cref="T:HslCommunication.Core.IMessage.INetMessage" /> 数据内容，需要指定超时时间，单位为毫秒。 <br />
		/// Receive a complete <seealso cref="T:HslCommunication.Core.IMessage.INetMessage" /> data content, Need to specify a timeout period in milliseconds
		/// </summary>
		/// <param name="socket">网络的套接字</param>
		/// <param name="timeOut">超时时间，单位：毫秒</param>
		/// <param name="netMessage">消息的格式定义</param>
		/// <param name="reportProgress">接收消息的时候的进度报告</param>
		/// <returns>带有是否成功的byte数组对象</returns>
		// Token: 0x060019EF RID: 6639 RVA: 0x00081934 File Offset: 0x0007FB34
		protected OperateResult<byte[]> ReceiveByMessage(Socket socket, int timeOut, INetMessage netMessage, Action<long, long> reportProgress = null)
		{
			bool flag = netMessage == null;
			OperateResult<byte[]> result;
			if (flag)
			{
				//接收缓冲区内所有的数据
				result = this.Receive(socket, -1, timeOut, null);
			}
			else
			{
				//根据消息格式接收一条完整数据
				OperateResult<byte[]> operateResult = this.Receive(socket, netMessage.ProtocolHeadBytesLength, timeOut, null);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = operateResult;
				}
				else
				{
					netMessage.HeadBytes = operateResult.Content;
					int contentLengthByHeadBytes = netMessage.GetContentLengthByHeadBytes();
					OperateResult<byte[]> operateResult2 = this.Receive(socket, contentLengthByHeadBytes, timeOut, reportProgress);
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = operateResult2;
					}
					else
					{
						netMessage.ContentBytes = operateResult2.Content;
						result = OperateResult.CreateSuccessResult<byte[]>(SoftBasic.SpliceArray<byte>(new byte[][]
						{
							operateResult.Content,
							operateResult2.Content
						}));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 发送消息给套接字，直到完成的时候返回，经过测试，本方法是线程安全的。<br />
		/// Send a message to the socket until it returns when completed. After testing, this method is thread-safe.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="data">字节数据</param>
		/// <returns>发送是否成功的结果</returns>
		// Token: 0x060019F0 RID: 6640 RVA: 0x000819E8 File Offset: 0x0007FBE8
		protected OperateResult Send(Socket socket, byte[] data)
		{
			bool flag = data == null;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateSuccessResult();
			}
			else
			{
				result = this.Send(socket, data, 0, data.Length);
			}
			return result;
		}

		/// <summary>
		/// 发送消息给套接字，直到完成的时候返回，经过测试，本方法是线程安全的。<br />
		/// Send a message to the socket until it returns when completed. After testing, this method is thread-safe.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="data">字节数据</param>
		/// <param name="offset">偏移的位置信息</param>
		/// <param name="size">发送的数据总数</param>
		/// <returns>发送是否成功的结果</returns>
		// Token: 0x060019F1 RID: 6641 RVA: 0x00081A18 File Offset: 0x0007FC18
		protected OperateResult Send(Socket socket, byte[] data, int offset, int size)
		{
			bool flag = data == null;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateSuccessResult();
			}
			else
			{
				bool flag2 = !Authorization.nzugaydgwadawdibbas();
				if (flag2)
				{
					result = new OperateResult<byte[]>(StringResources.Language.AuthorizationFailed);
				}
				else
				{
					try
					{
						int num = 0;
						bool flag3;
						do
						{
							//确保发送完毕
							int num2 = socket.Send(data, offset, size - num, SocketFlags.None);
							num += num2;
							offset += num2;
							flag3 = (num >= size);
						}
						while (!flag3);
						result = OperateResult.CreateSuccessResult();
					}
					catch (Exception ex)
					{
						if (socket != null)
						{
							socket.Close();
						}
						bool flag4 = this.connectErrorCount < 1000000000;
						if (flag4)
						{
							this.connectErrorCount++;
						}
						result = new OperateResult<byte[]>(-this.connectErrorCount, ex.Message);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 创建一个新的socket对象并连接到远程的地址，默认超时时间为10秒钟，需要指定ip地址以及端口号信息<br />
		/// Create a new socket object and connect to the remote address. The default timeout is 10 seconds. You need to specify the IP address and port number.
		/// </summary>
		/// <param name="ipAddress">Ip地址</param>
		/// <param name="port">端口号</param>
		/// <returns>返回套接字的封装结果对象</returns>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="CreateSocketAndConnectExample" title="创建连接示例" />
		/// </example>
		// Token: 0x060019F2 RID: 6642 RVA: 0x00081AF0 File Offset: 0x0007FCF0
		protected OperateResult<Socket> CreateSocketAndConnect(string ipAddress, int port)
		{
			return this.CreateSocketAndConnect(new IPEndPoint(IPAddress.Parse(ipAddress), port), 10000);
		}

		/// <summary>
		/// 创建一个新的socket对象并连接到远程的地址，需要指定ip地址以及端口号信息，还有超时时间，单位是毫秒<br />
		/// To create a new socket object and connect to a remote address, you need to specify the IP address and port number information, and the timeout period in milliseconds
		/// </summary>
		/// <param name="ipAddress">Ip地址</param>
		/// <param name="port">端口号</param>
		/// <param name="timeOut">连接的超时时间</param>
		/// <returns>返回套接字的封装结果对象</returns>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="CreateSocketAndConnectExample" title="创建连接示例" />
		/// </example>
		// Token: 0x060019F3 RID: 6643 RVA: 0x00081B09 File Offset: 0x0007FD09
		protected OperateResult<Socket> CreateSocketAndConnect(string ipAddress, int port, int timeOut)
		{
			return this.CreateSocketAndConnect(new IPEndPoint(IPAddress.Parse(ipAddress), port), timeOut);
		}

		/// <summary>
		/// 创建一个新的socket对象并连接到远程的地址，需要指定远程终结点，超时时间（单位是毫秒）<br />
		/// To create a new socket object and connect to a remote address, you need to specify the remote endpoint and the timeout period (in milliseconds)
		/// </summary>
		/// <param name="endPoint">连接的目标终结点</param>
		/// <param name="timeOut">连接的超时时间</param>
		/// <returns>返回套接字的封装结果对象</returns>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetworkBase.cs" region="CreateSocketAndConnectExample" title="创建连接示例" />
		/// </example>
		// Token: 0x060019F4 RID: 6644 RVA: 0x00081B20 File Offset: 0x0007FD20
		protected OperateResult<Socket> CreateSocketAndConnect(IPEndPoint endPoint, int timeOut)
		{
			int num = 0;
			OperateResult<Socket> result;
			for (;;)
			{
				num++;
				Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
				HslTimeOut hslTimeOut = HslTimeOut.HandleTimeOutCheck(socket, timeOut);
				try
				{
					socket.Connect(endPoint);
					this.connectErrorCount = 0;
					hslTimeOut.IsSuccessful = true;
					result = OperateResult.CreateSuccessResult<Socket>(socket);
					break;
				}
				catch (Exception ex)
				{
					if (socket != null)
					{
						socket.Close();
					}
					hslTimeOut.IsSuccessful = true;
					bool flag = this.connectErrorCount < 1000000000;
					if (flag)
					{
						this.connectErrorCount++;
					}
					bool flag2 = hslTimeOut.GetConsumeTime() < TimeSpan.FromMilliseconds(500.0) && num < 2;
					if (flag2)
					{
						Thread.Sleep(100);
					}
					else
					{
						bool isTimeout = hslTimeOut.IsTimeout;
						if (isTimeout)
						{
							result = new OperateResult<Socket>(-this.connectErrorCount, string.Format(StringResources.Language.ConnectTimeout, endPoint, timeOut) + " ms");
							break;
						}
						result = new OperateResult<Socket>(-this.connectErrorCount, string.Format("Socket Connect {0} Exception -> ", endPoint) + ex.Message);
						break;
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 读取流中的数据到缓存区，读取的长度需要按照实际的情况来判断<br />
		/// Read the data in the stream to the buffer area. The length of the read needs to be determined according to the actual situation.
		/// </summary>
		/// <param name="stream">数据流</param>
		/// <param name="buffer">缓冲区</param>
		/// <returns>带有成功标志的读取数据长度</returns>
		// Token: 0x060019F5 RID: 6645 RVA: 0x00081C58 File Offset: 0x0007FE58
		protected OperateResult<int> ReadStream(Stream stream, byte[] buffer)
		{
			ManualResetEvent manualResetEvent = new ManualResetEvent(false);
			FileStateObject fileStateObject = new FileStateObject
			{
				WaitDone = manualResetEvent,
				Stream = stream,
				DataLength = buffer.Length,
				Buffer = buffer
			};
			try
			{
				stream.BeginRead(buffer, 0, fileStateObject.DataLength, new AsyncCallback(this.ReadStreamCallBack), fileStateObject);
			}
			catch (Exception ex)
			{
				fileStateObject = null;
				manualResetEvent.Close();
				return new OperateResult<int>("stream.BeginRead Exception -> " + ex.Message);
			}
			manualResetEvent.WaitOne();
			manualResetEvent.Close();
			return fileStateObject.IsError ? new OperateResult<int>(fileStateObject.ErrerMsg) : OperateResult.CreateSuccessResult<int>(fileStateObject.AlreadyDealLength);
		}

		// Token: 0x060019F6 RID: 6646 RVA: 0x00081D1C File Offset: 0x0007FF1C
		private void ReadStreamCallBack(IAsyncResult ar)
		{
			FileStateObject fileStateObject = ar.AsyncState as FileStateObject;
			bool flag = fileStateObject != null;
			if (flag)
			{
				try
				{
					fileStateObject.AlreadyDealLength += fileStateObject.Stream.EndRead(ar);
					fileStateObject.WaitDone.Set();
				}
				catch (Exception ex)
				{
					fileStateObject.IsError = true;
					fileStateObject.ErrerMsg = ex.Message;
					fileStateObject.WaitDone.Set();
				}
			}
		}

		/// <summary>
		/// 将缓冲区的数据写入到流里面去<br />
		/// Write the buffer data to the stream
		/// </summary>
		/// <param name="stream">数据流</param>
		/// <param name="buffer">缓冲区</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x060019F7 RID: 6647 RVA: 0x00081DA0 File Offset: 0x0007FFA0
		protected OperateResult WriteStream(Stream stream, byte[] buffer)
		{
			ManualResetEvent manualResetEvent = new ManualResetEvent(false);
			FileStateObject fileStateObject = new FileStateObject
			{
				WaitDone = manualResetEvent,
				Stream = stream
			};
			try
			{
				stream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(this.WriteStreamCallBack), fileStateObject);
			}
			catch (Exception ex)
			{
				fileStateObject = null;
				manualResetEvent.Close();
				return new OperateResult("stream.BeginWrite Exception -> " + ex.Message);
			}
			manualResetEvent.WaitOne();
			manualResetEvent.Close();
			bool isError = fileStateObject.IsError;
			OperateResult result;
			if (isError)
			{
				result = new OperateResult
				{
					Message = fileStateObject.ErrerMsg
				};
			}
			else
			{
				result = OperateResult.CreateSuccessResult();
			}
			return result;
		}

		// Token: 0x060019F8 RID: 6648 RVA: 0x00081E58 File Offset: 0x00080058
		private void WriteStreamCallBack(IAsyncResult ar)
		{
			FileStateObject fileStateObject = ar.AsyncState as FileStateObject;
			bool flag = fileStateObject != null;
			if (flag)
			{
				try
				{
					fileStateObject.Stream.EndWrite(ar);
				}
				catch (Exception ex)
				{
					fileStateObject.IsError = true;
					fileStateObject.ErrerMsg = ex.Message;
				}
				finally
				{
					fileStateObject.WaitDone.Set();
				}
			}
		}

		/// <summary>
		/// 检查当前的头子节信息的令牌是否是正确的，仅用于某些特殊的协议实现<br />
		/// Check whether the token of the current header subsection information is correct, only for some special protocol implementations
		/// </summary>
		/// <param name="headBytes">头子节数据</param>
		/// <returns>令牌是验证成功</returns>
		// Token: 0x060019F9 RID: 6649 RVA: 0x00081ED4 File Offset: 0x000800D4
		protected bool CheckRemoteToken(byte[] headBytes)
		{
			return SoftBasic.IsByteTokenEquel(headBytes, this.Token);
		}

		/// <summary>
		/// [自校验] 发送字节数据并确认对方接收完成数据，如果结果异常，则结束通讯<br />
		/// [Self-check] Send the byte data and confirm that the other party has received the completed data. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="headCode">头指令</param>
		/// <param name="customer">用户指令</param>
		/// <param name="send">发送的数据</param>
		/// <returns>是否发送成功</returns>
		// Token: 0x060019FA RID: 6650 RVA: 0x00081EE4 File Offset: 0x000800E4
		protected OperateResult SendBaseAndCheckReceive(Socket socket, int headCode, int customer, byte[] send)
		{
			send = HslProtocol.CommandBytes(headCode, customer, this.Token, send);
			OperateResult operateResult = this.Send(socket, send);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<long> operateResult2 = this.ReceiveLong(socket);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content != (long)send.Length;
					if (flag3)
					{
						if (socket != null)
						{
							socket.Close();
						}
						result = new OperateResult(StringResources.Language.CommandLengthCheckFailed);
					}
					else
					{
						result = operateResult2;
					}
				}
			}
			return result;
		}

		/// <summary>
		/// [自校验] 发送字节数据并确认对方接收完成数据，如果结果异常，则结束通讯<br />
		/// [Self-check] Send the byte data and confirm that the other party has received the completed data. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="customer">用户指令</param>
		/// <param name="send">发送的数据</param>
		/// <returns>是否发送成功</returns>
		// Token: 0x060019FB RID: 6651 RVA: 0x00081F73 File Offset: 0x00080173
		protected OperateResult SendBytesAndCheckReceive(Socket socket, int customer, byte[] send)
		{
			return this.SendBaseAndCheckReceive(socket, 1002, customer, send);
		}

		/// <summary>
		/// [自校验] 直接发送字符串数据并确认对方接收完成数据，如果结果异常，则结束通讯<br />
		/// [Self-checking] Send string data directly and confirm that the other party has received the completed data. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="customer">用户指令</param>
		/// <param name="send">发送的数据</param>
		/// <returns>是否发送成功</returns>
		// Token: 0x060019FC RID: 6652 RVA: 0x00081F84 File Offset: 0x00080184
		protected OperateResult SendStringAndCheckReceive(Socket socket, int customer, string send)
		{
			byte[] send2 = string.IsNullOrEmpty(send) ? null : Encoding.Unicode.GetBytes(send);
			return this.SendBaseAndCheckReceive(socket, 1001, customer, send2);
		}

		/// <summary>
		/// [自校验] 直接发送字符串数组并确认对方接收完成数据，如果结果异常，则结束通讯<br />
		/// [Self-check] Send string array directly and confirm that the other party has received the completed data. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="customer">用户指令</param>
		/// <param name="sends">发送的字符串数组</param>
		/// <returns>是否发送成功</returns>
		// Token: 0x060019FD RID: 6653 RVA: 0x00081FBC File Offset: 0x000801BC
		protected OperateResult SendStringAndCheckReceive(Socket socket, int customer, string[] sends)
		{
			return this.SendBaseAndCheckReceive(socket, 1005, customer, HslProtocol.PackStringArrayToByte(sends));
		}

		/// <summary>
		/// [自校验] 直接发送字符串数组并确认对方接收完成数据，如果结果异常，则结束通讯<br />
		/// [Self-check] Send string array directly and confirm that the other party has received the completed data. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="customer">用户指令</param>
		/// <param name="name">用户名</param>
		/// <param name="pwd">密码</param>
		/// <returns>是否发送成功</returns>
		// Token: 0x060019FE RID: 6654 RVA: 0x00081FE4 File Offset: 0x000801E4
		protected OperateResult SendAccountAndCheckReceive(Socket socket, int customer, string name, string pwd)
		{
			return this.SendBaseAndCheckReceive(socket, 5, customer, HslProtocol.PackStringArrayToByte(new string[]
			{
				name,
				pwd
			}));
		}

		/// <summary>
		/// [自校验] 接收一条完整的同步数据，包含头子节和内容字节，基础的数据，如果结果异常，则结束通讯<br />
		/// [Self-checking] Receive a complete synchronization data, including header subsection and content bytes, basic data, if the result is abnormal, the communication ends
		/// </summary>
		/// <param name="socket">套接字</param>
		/// <param name="timeOut">超时时间设置，如果为负数，则不检查超时</param>
		/// <returns>包含是否成功的结果对象</returns>
		/// <exception cref="T:System.ArgumentNullException">result</exception>
		// Token: 0x060019FF RID: 6655 RVA: 0x00082014 File Offset: 0x00080214
		protected OperateResult<byte[], byte[]> ReceiveAndCheckBytes(Socket socket, int timeOut)
		{
			OperateResult<byte[]> operateResult = this.Receive(socket, 32, timeOut, null);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[], byte[]> result;
			if (flag)
			{
				result = operateResult.ConvertFailed<byte[], byte[]>();
			}
			else
			{
				bool flag2 = !this.CheckRemoteToken(operateResult.Content);
				if (flag2)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = new OperateResult<byte[], byte[]>(StringResources.Language.TokenCheckFailed);
				}
				else
				{
					int num = BitConverter.ToInt32(operateResult.Content, 28);
					OperateResult<byte[]> operateResult2 = this.Receive(socket, num, timeOut, null);
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = operateResult2.ConvertFailed<byte[], byte[]>();
					}
					else
					{
						OperateResult operateResult3 = this.SendLong(socket, (long)(32 + num));
						bool flag4 = !operateResult3.IsSuccess;
						if (flag4)
						{
							result = operateResult3.ConvertFailed<byte[], byte[]>();
						}
						else
						{
							byte[] content = operateResult.Content;
							byte[] array = operateResult2.Content;
							array = HslProtocol.CommandAnalysis(content, array);
							result = OperateResult.CreateSuccessResult<byte[], byte[]>(content, array);
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// [自校验] 从网络中接收一个字符串数据，如果结果异常，则结束通讯<br />
		/// [Self-checking] Receive a string of data from the network. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">套接字</param>
		/// <param name="timeOut">接收数据的超时时间</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06001A00 RID: 6656 RVA: 0x00082104 File Offset: 0x00080304
		protected OperateResult<int, string> ReceiveStringContentFromSocket(Socket socket, int timeOut = 30000)
		{
			OperateResult<byte[], byte[]> operateResult = this.ReceiveAndCheckBytes(socket, timeOut);
			bool flag = !operateResult.IsSuccess;
			OperateResult<int, string> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<int, string>(operateResult);
			}
			else
			{
				bool flag2 = BitConverter.ToInt32(operateResult.Content1, 0) != 1001;
				if (flag2)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = new OperateResult<int, string>(StringResources.Language.CommandHeadCodeCheckFailed);
				}
				else
				{
					bool flag3 = operateResult.Content2 == null;
					if (flag3)
					{
						operateResult.Content2 = new byte[0];
					}
					result = OperateResult.CreateSuccessResult<int, string>(BitConverter.ToInt32(operateResult.Content1, 4), Encoding.Unicode.GetString(operateResult.Content2));
				}
			}
			return result;
		}

		/// <summary>
		/// [自校验] 从网络中接收一个字符串数组，如果结果异常，则结束通讯<br />
		/// [Self-check] Receive an array of strings from the network. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">套接字</param>
		/// <param name="timeOut">接收数据的超时时间</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06001A01 RID: 6657 RVA: 0x000821AC File Offset: 0x000803AC
		protected OperateResult<int, string[]> ReceiveStringArrayContentFromSocket(Socket socket, int timeOut = 30000)
		{
			OperateResult<byte[], byte[]> operateResult = this.ReceiveAndCheckBytes(socket, timeOut);
			bool flag = !operateResult.IsSuccess;
			OperateResult<int, string[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<int, string[]>(operateResult);
			}
			else
			{
				bool flag2 = BitConverter.ToInt32(operateResult.Content1, 0) != 1005;
				if (flag2)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = new OperateResult<int, string[]>(StringResources.Language.CommandHeadCodeCheckFailed);
				}
				else
				{
					bool flag3 = operateResult.Content2 == null;
					if (flag3)
					{
						operateResult.Content2 = new byte[4];
					}
					result = OperateResult.CreateSuccessResult<int, string[]>(BitConverter.ToInt32(operateResult.Content1, 4), HslProtocol.UnPackStringArrayFromByte(operateResult.Content2));
				}
			}
			return result;
		}

		/// <summary>
		/// [自校验] 从网络中接收一串字节数据，如果结果异常，则结束通讯<br />
		/// [Self-checking] Receive a string of byte data from the network. If the result is abnormal, the communication ends.
		/// </summary>
		/// <param name="socket">套接字的网络</param>
		/// <param name="timeout">超时时间</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06001A02 RID: 6658 RVA: 0x00082250 File Offset: 0x00080450
		protected OperateResult<int, byte[]> ReceiveBytesContentFromSocket(Socket socket, int timeout = 30000)
		{
			OperateResult<byte[], byte[]> operateResult = this.ReceiveAndCheckBytes(socket, timeout);
			bool flag = !operateResult.IsSuccess;
			OperateResult<int, byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<int, byte[]>(operateResult);
			}
			else
			{
				bool flag2 = BitConverter.ToInt32(operateResult.Content1, 0) != 1002;
				if (flag2)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = new OperateResult<int, byte[]>(StringResources.Language.CommandHeadCodeCheckFailed);
				}
				else
				{
					result = OperateResult.CreateSuccessResult<int, byte[]>(BitConverter.ToInt32(operateResult.Content1, 4), operateResult.Content2);
				}
			}
			return result;
		}

		/// <summary>
		/// 从网络中接收Long数据<br />
		/// Receive Long data from the network
		/// </summary>
		/// <param name="socket">套接字网络</param>
		/// <returns>long数据结果</returns>
		// Token: 0x06001A03 RID: 6659 RVA: 0x000822D4 File Offset: 0x000804D4
		private OperateResult<long> ReceiveLong(Socket socket)
		{
			OperateResult<byte[]> operateResult = this.Receive(socket, 8, -1, null);
			bool isSuccess = operateResult.IsSuccess;
			OperateResult<long> result;
			if (isSuccess)
			{
				result = OperateResult.CreateSuccessResult<long>(BitConverter.ToInt64(operateResult.Content, 0));
			}
			else
			{
				result = OperateResult.CreateFailedResult<long>(operateResult);
			}
			return result;
		}

		/// <summary>
		/// 将long数据发送到套接字<br />
		/// Send long data to the socket
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="value">long数据</param>
		/// <returns>是否发送成功</returns>
		// Token: 0x06001A04 RID: 6660 RVA: 0x00082315 File Offset: 0x00080515
		private OperateResult SendLong(Socket socket, long value)
		{
			return this.Send(socket, BitConverter.GetBytes(value));
		}

		/// <summary>
		/// 发送一个流的所有数据到指定的网络套接字，需要指定发送的数据长度，支持按照百分比的进度报告<br />
		/// Send all the data of a stream to the specified network socket. You need to specify the length of the data to be sent. It supports the progress report in percentage.
		/// </summary>
		/// <param name="socket">套接字</param>
		/// <param name="stream">内存流</param>
		/// <param name="receive">发送的数据长度</param>
		/// <param name="report">进度报告的委托</param>
		/// <param name="reportByPercent">进度报告是否按照百分比报告</param>
		/// <returns>是否成功的结果对象</returns>
		// Token: 0x06001A05 RID: 6661 RVA: 0x00082324 File Offset: 0x00080524
		protected OperateResult SendStreamToSocket(Socket socket, Stream stream, long receive, Action<long, long> report, bool reportByPercent)
		{
			byte[] array = new byte[this.fileCacheSize];
			long num = 0L;
			long num2 = 0L;
			stream.Position = 0L;
			while (num < receive)
			{
				OperateResult<int> operateResult = this.ReadStream(stream, array);
				bool flag = !operateResult.IsSuccess;
				OperateResult result;
				if (flag)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = operateResult;
				}
				else
				{
					num += (long)operateResult.Content;
					byte[] array2 = new byte[operateResult.Content];
					Array.Copy(array, 0, array2, 0, array2.Length);
					OperateResult operateResult2 = this.SendBytesAndCheckReceive(socket, operateResult.Content, array2);
					bool flag2 = !operateResult2.IsSuccess;
					if (!flag2)
					{
						if (reportByPercent)
						{
							long num3 = num * 100L / receive;
							bool flag3 = num2 != num3;
							if (flag3)
							{
								num2 = num3;
								if (report != null)
								{
									report(num, receive);
								}
							}
						}
						else if (report != null)
						{
							report(num, receive);
						}
						continue;
					}
					if (socket != null)
					{
						socket.Close();
					}
					result = operateResult2;
				}
				return result;
			}
			return OperateResult.CreateSuccessResult();
		}

		/// <summary>
		/// 从套接字中接收所有的数据然后写入到指定的流当中去，需要指定数据的长度，支持按照百分比进行进度报告<br />
		/// Receives all data from the socket and writes it to the specified stream. The length of the data needs to be specified, and progress reporting is supported in percentage.
		/// </summary>
		/// <param name="socket">套接字</param>
		/// <param name="stream">数据流</param>
		/// <param name="totalLength">所有数据的长度</param>
		/// <param name="report">进度报告</param>
		/// <param name="reportByPercent">进度报告是否按照百分比</param>
		/// <returns>是否成功的结果对象</returns>
		// Token: 0x06001A06 RID: 6662 RVA: 0x00082440 File Offset: 0x00080640
		protected OperateResult WriteStreamFromSocket(Socket socket, Stream stream, long totalLength, Action<long, long> report, bool reportByPercent)
		{
			long num = 0L;
			long num2 = 0L;
			while (num < totalLength)
			{
				OperateResult<int, byte[]> operateResult = this.ReceiveBytesContentFromSocket(socket, 60000);
				bool flag = !operateResult.IsSuccess;
				OperateResult result;
				if (flag)
				{
					result = operateResult;
				}
				else
				{
					num += (long)operateResult.Content1;
					OperateResult operateResult2 = this.WriteStream(stream, operateResult.Content2);
					bool flag2 = !operateResult2.IsSuccess;
					if (!flag2)
					{
						if (reportByPercent)
						{
							long num3 = num * 100L / totalLength;
							bool flag3 = num2 != num3;
							if (flag3)
							{
								num2 = num3;
								if (report != null)
								{
									report(num, totalLength);
								}
							}
						}
						else if (report != null)
						{
							report(num, totalLength);
						}
						continue;
					}
					if (socket != null)
					{
						socket.Close();
					}
					result = operateResult2;
				}
				return result;
			}
			return OperateResult.CreateSuccessResult();
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.CreateSocketAndConnect(System.Net.IPEndPoint,System.Int32)" />
		// Token: 0x06001A07 RID: 6663 RVA: 0x0008251C File Offset: 0x0008071C
		[DebuggerStepThrough]
		protected Task<OperateResult<Socket>> CreateSocketAndConnectAsync(IPEndPoint endPoint, int timeOut)
		{
			return Task.Run(() => CreateSocketAndConnect(endPoint, timeOut));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.CreateSocketAndConnect(System.String,System.Int32)" />
		// Token: 0x06001A08 RID: 6664 RVA: 0x00082570 File Offset: 0x00080770
		[DebuggerStepThrough]
		protected Task<OperateResult<Socket>> CreateSocketAndConnectAsync(string ipAddress, int port)
		{
			return Task.Run(() =>  CreateSocketAndConnect(ipAddress, port));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.CreateSocketAndConnect(System.String,System.Int32,System.Int32)" />
		// Token: 0x06001A09 RID: 6665 RVA: 0x000825C4 File Offset: 0x000807C4
		[DebuggerStepThrough]
		protected Task<OperateResult<Socket>> CreateSocketAndConnectAsync(string ipAddress, int port, int timeOut)
		{
			return Task.Run(() =>  CreateSocketAndConnect(ipAddress, port, timeOut));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.Receive(System.Net.Sockets.Socket,System.Int32,System.Int32,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A0A RID: 6666 RVA: 0x00082620 File Offset: 0x00080820
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[]>> ReceiveAsync(Socket socket, int length, int timeOut = 60000, Action<long, long> reportProgress = null)
		{
			return Task.Run(() => Receive(socket, length, timeOut, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveCommandLineFromSocket(System.Net.Sockets.Socket,System.Byte,System.Int32)" />
		// Token: 0x06001A0B RID: 6667 RVA: 0x00082684 File Offset: 0x00080884
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[]>> ReceiveCommandLineFromSocketAsync(Socket socket, byte endCode, int timeout = 2147483647)
		{
			return Task.Run(() =>  ReceiveCommandLineFromSocket(socket, endCode, timeout));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveCommandLineFromSocket(System.Net.Sockets.Socket,System.Byte,System.Byte,System.Int32)" />
		// Token: 0x06001A0C RID: 6668 RVA: 0x000826E0 File Offset: 0x000808E0
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[]>> ReceiveCommandLineFromSocketAsync(Socket socket, byte endCode1, byte endCode2, int timeout = 60000)
		{
			return Task.Run(() =>  ReceiveCommandLineFromSocket(socket, endCode1, endCode2, timeout));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.Send(System.Net.Sockets.Socket,System.Byte[])" />
		// Token: 0x06001A0D RID: 6669 RVA: 0x00082744 File Offset: 0x00080944
		[DebuggerStepThrough]
		protected Task<OperateResult> SendAsync(Socket socket, byte[] data)
		{
			return Task.Run(() => Send(socket, data));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.Send(System.Net.Sockets.Socket,System.Byte[],System.Int32,System.Int32)" />
		// Token: 0x06001A0E RID: 6670 RVA: 0x00082798 File Offset: 0x00080998
		[DebuggerStepThrough]
		protected Task<OperateResult> SendAsync(Socket socket, byte[] data, int offset, int size)
		{
			return Task.Run(() => Send(socket, data, offset, size));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveByMessage(System.Net.Sockets.Socket,System.Int32,HslCommunication.Core.IMessage.INetMessage,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A0F RID: 6671 RVA: 0x000827FC File Offset: 0x000809FC
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[]>> ReceiveByMessageAsync(Socket socket, int timeOut, INetMessage netMessage, Action<long, long> reportProgress = null)
		{
			return Task.Run(()=>ReceiveByMessage(socket, timeOut, netMessage, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReadStream(System.IO.Stream,System.Byte[])" />
		// Token: 0x06001A10 RID: 6672 RVA: 0x00082860 File Offset: 0x00080A60
		[DebuggerStepThrough]
		protected Task<OperateResult<int>> ReadStreamAsync(Stream stream, byte[] buffer)
		{
			return Task.Run(()=>ReadStream(stream, buffer));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.WriteStream(System.IO.Stream,System.Byte[])" />
		// Token: 0x06001A11 RID: 6673 RVA: 0x000828B4 File Offset: 0x00080AB4
		[DebuggerStepThrough]
		protected Task<OperateResult> WriteStreamAsync(Stream stream, byte[] buffer)
		{
			return Task.Run(()=>WriteStream(stream, buffer));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveLong(System.Net.Sockets.Socket)" />
		// Token: 0x06001A12 RID: 6674 RVA: 0x00082908 File Offset: 0x00080B08
		[DebuggerStepThrough]
		private Task<OperateResult<long>> ReceiveLongAsync(Socket socket)
		{
			return Task.Run(() => ReceiveLong(socket));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendLong(System.Net.Sockets.Socket,System.Int64)" />
		// Token: 0x06001A13 RID: 6675 RVA: 0x00082954 File Offset: 0x00080B54
		[DebuggerStepThrough]
		private Task<OperateResult> SendLongAsync(Socket socket, long value)
		{
			return Task.Run(()=>SendLong(socket, value));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendBaseAndCheckReceive(System.Net.Sockets.Socket,System.Int32,System.Int32,System.Byte[])" />
		// Token: 0x06001A14 RID: 6676 RVA: 0x000829A8 File Offset: 0x00080BA8
		[DebuggerStepThrough]
		protected Task<OperateResult> SendBaseAndCheckReceiveAsync(Socket socket, int headCode, int customer, byte[] send)
		{
			return Task.Run(()=>SendBaseAndCheckReceive(socket, headCode, customer, send));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendBytesAndCheckReceive(System.Net.Sockets.Socket,System.Int32,System.Byte[])" />
		// Token: 0x06001A15 RID: 6677 RVA: 0x00082A0C File Offset: 0x00080C0C
		[DebuggerStepThrough]
		protected Task<OperateResult> SendBytesAndCheckReceiveAsync(Socket socket, int customer, byte[] send)
		{
			return Task.Run(()=>SendBytesAndCheckReceive(socket, customer, send));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendStringAndCheckReceive(System.Net.Sockets.Socket,System.Int32,System.String)" />
		// Token: 0x06001A16 RID: 6678 RVA: 0x00082A68 File Offset: 0x00080C68
		[DebuggerStepThrough]
		protected Task<OperateResult> SendStringAndCheckReceiveAsync(Socket socket, int customer, string send)
		{
			return Task.Run(()=>SendStringAndCheckReceive(socket, customer, send));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendStringAndCheckReceive(System.Net.Sockets.Socket,System.Int32,System.String[])" />
		// Token: 0x06001A17 RID: 6679 RVA: 0x00082AC4 File Offset: 0x00080CC4
		[DebuggerStepThrough]
		protected Task<OperateResult> SendStringAndCheckReceiveAsync(Socket socket, int customer, string[] sends)
		{
			return Task.Run(()=>SendStringAndCheckReceive(socket, customer, sends));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendAccountAndCheckReceive(System.Net.Sockets.Socket,System.Int32,System.String,System.String)" />
		// Token: 0x06001A18 RID: 6680 RVA: 0x00082B20 File Offset: 0x00080D20
		[DebuggerStepThrough]
		protected Task<OperateResult> SendAccountAndCheckReceiveAsync(Socket socket, int customer, string name, string pwd)
		{
			return Task.Run(()=>SendAccountAndCheckReceive(socket, customer, name, pwd));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveAndCheckBytes(System.Net.Sockets.Socket,System.Int32)" />
		// Token: 0x06001A19 RID: 6681 RVA: 0x00082B84 File Offset: 0x00080D84
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[], byte[]>> ReceiveAndCheckBytesAsync(Socket socket, int timeout)
		{
			return Task.Run(()=>ReceiveAndCheckBytes(socket, timeout));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveStringContentFromSocket(System.Net.Sockets.Socket,System.Int32)" />
		// Token: 0x06001A1A RID: 6682 RVA: 0x00082BD8 File Offset: 0x00080DD8
		[DebuggerStepThrough]
		protected Task<OperateResult<int, string>> ReceiveStringContentFromSocketAsync(Socket socket, int timeOut = 30000)
		{
			return Task.Run(() => ReceiveStringContentFromSocket(socket, timeOut));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveStringArrayContentFromSocket(System.Net.Sockets.Socket,System.Int32)" />
		// Token: 0x06001A1B RID: 6683 RVA: 0x00082C2C File Offset: 0x00080E2C
		[DebuggerStepThrough]
		protected Task<OperateResult<int, string[]>> ReceiveStringArrayContentFromSocketAsync(Socket socket, int timeOut = 30000)
		{
			return Task.Run(()=>ReceiveStringArrayContentFromSocket(socket, timeOut));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveBytesContentFromSocket(System.Net.Sockets.Socket,System.Int32)" />
		// Token: 0x06001A1C RID: 6684 RVA: 0x00082C80 File Offset: 0x00080E80
		[DebuggerStepThrough]
		protected Task<OperateResult<int, byte[]>> ReceiveBytesContentFromSocketAsync(Socket socket, int timeout = 30000)
		{
			return Task.Run(()=>ReceiveBytesContentFromSocket(socket, timeout));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendStreamToSocket(System.Net.Sockets.Socket,System.IO.Stream,System.Int64,System.Action{System.Int64,System.Int64},System.Boolean)" />
		// Token: 0x06001A1D RID: 6685 RVA: 0x00082CD4 File Offset: 0x00080ED4
		[DebuggerStepThrough]
		protected Task<OperateResult> SendStreamToSocketAsync(Socket socket, Stream stream, long receive, Action<long, long> report, bool reportByPercent)
		{
			return Task.Run(() => SendStreamToSocket(socket, stream, receive, report, reportByPercent));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.WriteStreamFromSocket(System.Net.Sockets.Socket,System.IO.Stream,System.Int64,System.Action{System.Int64,System.Int64},System.Boolean)" />
		// Token: 0x06001A1E RID: 6686 RVA: 0x00082D40 File Offset: 0x00080F40
		[DebuggerStepThrough]
		protected Task<OperateResult> WriteStreamFromSocketAsync(Socket socket, Stream stream, long totalLength, Action<long, long> report, bool reportByPercent)
		{
			return Task.Run(() => WriteStreamFromSocket(socket, stream, totalLength, report, reportByPercent));
		}

		/// <summary>
		/// 从socket接收一条完整的websocket数据，返回<see cref="T:HslCommunication.WebSocket.WebSocketMessage" />的数据信息<br />
		/// Receive a complete websocket data from the socket, return the data information of the <see cref="T:HslCommunication.WebSocket.WebSocketMessage" />
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <returns>包含websocket消息的结果内容</returns>
		// Token: 0x06001A1F RID: 6687 RVA: 0x00082DAC File Offset: 0x00080FAC
		protected OperateResult<WebSocketMessage> ReceiveWebSocketPayload(Socket socket)
		{
			List<byte> list = new List<byte>();
			OperateResult<WebSocketMessage, bool> operateResult;
			for (;;)
			{
				operateResult = this.ReceiveFrameWebSocketPayload(socket);
				bool flag = !operateResult.IsSuccess;
				if (flag)
				{
					break;
				}
				list.AddRange(operateResult.Content1.Payload);
				bool content = operateResult.Content2;
				if (content)
				{
					goto Block_2;
				}
			}
			return OperateResult.CreateFailedResult<WebSocketMessage>(operateResult);
			Block_2:
			return OperateResult.CreateSuccessResult<WebSocketMessage>(new WebSocketMessage
			{
				HasMask = operateResult.Content1.HasMask,
				OpCode = operateResult.Content1.OpCode,
				Payload = list.ToArray()
			});
		}

		/// <summary>
		/// 从socket接收一条<see cref="T:HslCommunication.WebSocket.WebSocketMessage" />片段数据，返回<see cref="T:HslCommunication.WebSocket.WebSocketMessage" />的数据信息和是否最后一条数据内容<br />
		/// Receive a piece of <see cref="T:HslCommunication.WebSocket.WebSocketMessage" /> fragment data from the socket, return the data information of <see cref="T:HslCommunication.WebSocket.WebSocketMessage" /> and whether the last data content
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <returns>包含websocket消息的结果内容</returns>
		// Token: 0x06001A20 RID: 6688 RVA: 0x00082E48 File Offset: 0x00081048
		protected OperateResult<WebSocketMessage, bool> ReceiveFrameWebSocketPayload(Socket socket)
		{
			OperateResult<byte[]> operateResult = this.Receive(socket, 2, 5000, null);
			bool flag = !operateResult.IsSuccess;
			OperateResult<WebSocketMessage, bool> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<WebSocketMessage, bool>(operateResult);
			}
			else
			{
				bool value = (operateResult.Content[0] & 128) == 128;
				bool flag2 = (operateResult.Content[1] & 128) == 128;
				int opCode = (int)(operateResult.Content[0] & 15);
				byte[] array = null;
				int num = (int)(operateResult.Content[1] & 127);
				bool flag3 = num == 126;
				if (flag3)
				{
					OperateResult<byte[]> operateResult2 = this.Receive(socket, 2, 5000, null);
					bool flag4 = !operateResult2.IsSuccess;
					if (flag4)
					{
						return OperateResult.CreateFailedResult<WebSocketMessage, bool>(operateResult2);
					}
					Array.Reverse(operateResult2.Content);
					num = (int)BitConverter.ToUInt16(operateResult2.Content, 0);
				}
				else
				{
					bool flag5 = num == 127;
					if (flag5)
					{
						OperateResult<byte[]> operateResult3 = this.Receive(socket, 8, 5000, null);
						bool flag6 = !operateResult3.IsSuccess;
						if (flag6)
						{
							return OperateResult.CreateFailedResult<WebSocketMessage, bool>(operateResult3);
						}
						Array.Reverse(operateResult3.Content);
						num = (int)BitConverter.ToUInt64(operateResult3.Content, 0);
					}
				}
				bool flag7 = flag2;
				if (flag7)
				{
					OperateResult<byte[]> operateResult4 = this.Receive(socket, 4, 5000, null);
					bool flag8 = !operateResult4.IsSuccess;
					if (flag8)
					{
						return OperateResult.CreateFailedResult<WebSocketMessage, bool>(operateResult4);
					}
					array = operateResult4.Content;
				}
				OperateResult<byte[]> operateResult5 = this.Receive(socket, num, 60000, null);
				bool flag9 = !operateResult5.IsSuccess;
				if (flag9)
				{
					result = OperateResult.CreateFailedResult<WebSocketMessage, bool>(operateResult5);
				}
				else
				{
					bool flag10 = flag2;
					if (flag10)
					{
						for (int i = 0; i < operateResult5.Content.Length; i++)
						{
							operateResult5.Content[i] = (byte)(operateResult5.Content[i] ^ array[i % 4]);
						}
					}
					result = OperateResult.CreateSuccessResult<WebSocketMessage, bool>(new WebSocketMessage
					{
						HasMask = flag2,
						OpCode = opCode,
						Payload = operateResult5.Content
					}, value);
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveWebSocketPayload(System.Net.Sockets.Socket)" />
		// Token: 0x06001A21 RID: 6689 RVA: 0x0008305C File Offset: 0x0008125C
		[DebuggerStepThrough]
		protected Task<OperateResult<WebSocketMessage>> ReceiveWebSocketPayloadAsync(Socket socket)
		{
			return Task.Run(()=>ReceiveWebSocketPayload(socket));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveFrameWebSocketPayload(System.Net.Sockets.Socket)" />
		// Token: 0x06001A22 RID: 6690 RVA: 0x000830A8 File Offset: 0x000812A8
		[DebuggerStepThrough]
		protected Task<OperateResult<WebSocketMessage, bool>> ReceiveFrameWebSocketPayloadAsync(Socket socket)
		{
			return Task.Run(()=>ReceiveFrameWebSocketPayload(socket));
		}

		/// <summary>
		/// 基于MQTT协议，从网络套接字中接收剩余的数据长度<br />
		/// Receives the remaining data length from the network socket based on the MQTT protocol
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <returns>网络中剩余的长度数据</returns>
		// Token: 0x06001A23 RID: 6691 RVA: 0x000830F4 File Offset: 0x000812F4
		private OperateResult<int> ReceiveMqttRemainingLength(Socket socket)
		{
			List<byte> list = new List<byte>();
			OperateResult<byte[]> operateResult;
			for (;;)
			{
				operateResult = this.Receive(socket, 1, 5000, null);
				bool flag = !operateResult.IsSuccess;
				if (flag)
				{
					break;
				}
				list.Add(operateResult.Content[0]);
				bool flag2 = operateResult.Content[0] < 128;
				if (flag2)
				{
					goto Block_2;
				}
				bool flag3 = list.Count >= 4;
				if (flag3)
				{
					goto Block_3;
				}
			}
			return OperateResult.CreateFailedResult<int>(operateResult);
			Block_2:
			Block_3:
			bool flag4 = list.Count > 4;
			OperateResult<int> result;
			if (flag4)
			{
				result = new OperateResult<int>("Receive Length is too long!");
			}
			else
			{
				bool flag5 = list.Count == 1;
				if (flag5)
				{
					result = OperateResult.CreateSuccessResult<int>((int)list[0]);
				}
				else
				{
					bool flag6 = list.Count == 2;
					if (flag6)
					{
						result = OperateResult.CreateSuccessResult<int>((int)(list[0] - 128 + list[1] * 128));
					}
					else
					{
						bool flag7 = list.Count == 3;
						if (flag7)
						{
							result = OperateResult.CreateSuccessResult<int>((int)(list[0] - 128 + (list[1] - 128) * 128 + list[2] * 128 * 128));
						}
						else
						{
							result = OperateResult.CreateSuccessResult<int>((int)(list[0] - 128 + (list[1] - 128) * 128 + (list[2] - 128) * 128 * 128 + list[3] * 128 * 128 * 128));
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 接收一条完整的MQTT协议的报文信息，包含控制码和负载数据<br />
		/// Receive a message of a completed MQTT protocol, including control code and payload data
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="timeOut">超时时间</param>
		/// <param name="reportProgress">进度报告，第一个参数是已完成的字节数量，第二个参数是总字节数量。</param>
		/// <returns>结果数据内容</returns>
		// Token: 0x06001A24 RID: 6692 RVA: 0x00083294 File Offset: 0x00081494
		protected OperateResult<byte, byte[]> ReceiveMqttMessage(Socket socket, int timeOut, Action<long, long> reportProgress = null)
		{
			OperateResult<byte[]> operateResult = this.Receive(socket, 1, timeOut, null);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte, byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte, byte[]>(operateResult);
			}
			else
			{
				OperateResult<int> operateResult2 = this.ReceiveMqttRemainingLength(socket);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte, byte[]>(operateResult2);
				}
				else
				{
					bool flag3 = operateResult.Content[0] >> 4 == 15;
					if (flag3)
					{
						reportProgress = null;
					}
					bool flag4 = operateResult.Content[0] >> 4 == 0;
					if (flag4)
					{
						reportProgress = null;
					}
					OperateResult<byte[]> operateResult3 = this.Receive(socket, operateResult2.Content, 60000, reportProgress);
					bool flag5 = !operateResult3.IsSuccess;
					if (flag5)
					{
						result = OperateResult.CreateFailedResult<byte, byte[]>(operateResult3);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<byte, byte[]>(operateResult.Content[0], operateResult3.Content);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 使用MQTT协议从socket接收指定长度的字节数组，然后全部写入到流中，可以指定进度报告<br />
		/// Use the MQTT protocol to receive a byte array of specified length from the socket, and then write all of them to the stream, and you can specify a progress report
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="stream">数据流</param>
		/// <param name="fileSize">数据大小</param>
		/// <param name="timeOut">超时时间</param>
		/// <param name="reportProgress">进度报告，第一个参数是已完成的字节数量，第二个参数是总字节数量。</param>
		/// <returns>是否操作成功</returns>
		// Token: 0x06001A25 RID: 6693 RVA: 0x0008335C File Offset: 0x0008155C
		protected OperateResult ReceiveMqttStream(Socket socket, Stream stream, long fileSize, int timeOut, Action<long, long> reportProgress = null)
		{
			long num = 0L;
			while (num < fileSize)
			{
				OperateResult<byte, byte[]> operateResult = this.ReceiveMqttMessage(socket, timeOut, null);
				bool flag = !operateResult.IsSuccess;
				OperateResult result;
				if (flag)
				{
					result = operateResult;
				}
				else
				{
					bool flag2 = operateResult.Content1 == 0;
					if (flag2)
					{
						if (socket != null)
						{
							socket.Close();
						}
						result = new OperateResult(Encoding.UTF8.GetString(operateResult.Content2));
					}
					else
					{
						OperateResult operateResult2 = this.WriteStream(stream, operateResult.Content2);
						bool flag3 = !operateResult2.IsSuccess;
						if (flag3)
						{
							result = operateResult2;
						}
						else
						{
							num += (long)operateResult.Content2.Length;
							byte[] array = new byte[16];
							BitConverter.GetBytes(num).CopyTo(array, 0);
							BitConverter.GetBytes(fileSize).CopyTo(array, 8);
							OperateResult operateResult3 = this.Send(socket, MqttHelper.BuildMqttCommand(100, null, array).Content);
							bool flag4 = !operateResult3.IsSuccess;
							if (!flag4)
							{
								if (reportProgress != null)
								{
									reportProgress(num, fileSize);
								}
								continue;
							}
							result = operateResult3;
						}
					}
				}
				return result;
			}
			return OperateResult.CreateSuccessResult();
		}

		/// <summary>
		/// 使用MQTT协议将流中的数据读取到字节数组，然后都写入到socket里面，可以指定进度报告，主要用于将文件发送到网络。<br />
		/// Use the MQTT protocol to read the data in the stream into a byte array, and then write them all into the socket. 
		/// You can specify a progress report, which is mainly used to send files to the network.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="stream">流</param>
		/// <param name="fileSize">总的数据大小</param>
		/// <param name="timeOut">超时信息</param>
		/// <param name="reportProgress">进度报告，第一个参数是已完成的字节数量，第二个参数是总字节数量。</param>
		/// <returns>是否操作成功</returns>
		// Token: 0x06001A26 RID: 6694 RVA: 0x00083478 File Offset: 0x00081678
		protected OperateResult SendMqttStream(Socket socket, Stream stream, long fileSize, int timeOut, Action<long, long> reportProgress = null)
		{
			byte[] array = new byte[this.fileCacheSize];
			long num = 0L;
			stream.Position = 0L;
			while (num < fileSize)
			{
				OperateResult<int> operateResult = this.ReadStream(stream, array);
				bool flag = !operateResult.IsSuccess;
				OperateResult result;
				if (flag)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = operateResult;
				}
				else
				{
					num += (long)operateResult.Content;
					OperateResult operateResult2 = this.Send(socket, MqttHelper.BuildMqttCommand(100, null, array.SelectBegin(operateResult.Content)).Content);
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						if (socket != null)
						{
							socket.Close();
						}
						result = operateResult2;
					}
					else
					{
						OperateResult<byte, byte[]> operateResult3 = this.ReceiveMqttMessage(socket, timeOut, null);
						bool flag3 = !operateResult3.IsSuccess;
						if (!flag3)
						{
							if (reportProgress != null)
							{
								reportProgress(num, fileSize);
							}
							continue;
						}
						result = operateResult3;
					}
				}
				return result;
			}
			return OperateResult.CreateSuccessResult();
		}

		/// <summary>
		/// 使用MQTT协议将一个文件发送到网络上去，需要指定文件名，保存的文件名，可选指定文件描述信息，进度报告<br />
		/// To send a file to the network using the MQTT protocol, you need to specify the file name, the saved file name, 
		/// optionally specify the file description information, and the progress report
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="filename">文件名称</param>
		/// <param name="servername">对方接收后保存的文件名</param>
		/// <param name="filetag">文件的描述信息</param>
		/// <param name="reportProgress">进度报告，第一个参数是已完成的字节数量，第二个参数是总字节数量。</param>
		/// <returns>是否操作成功</returns>
		// Token: 0x06001A27 RID: 6695 RVA: 0x00083568 File Offset: 0x00081768
		protected OperateResult SendMqttFile(Socket socket, string filename, string servername, string filetag, Action<long, long> reportProgress = null)
		{
			FileInfo fileInfo = new FileInfo(filename);
			bool flag = !File.Exists(filename);
			OperateResult result;
			if (flag)
			{
				OperateResult operateResult = this.Send(socket, MqttHelper.BuildMqttCommand(0, null, Encoding.UTF8.GetBytes(StringResources.Language.FileNotExist)).Content);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = operateResult;
				}
				else
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = new OperateResult(StringResources.Language.FileNotExist);
				}
			}
			else
			{
				string[] data = new string[]
				{
					servername,
					fileInfo.Length.ToString(),
					filetag
				};
				OperateResult operateResult2 = this.Send(socket, MqttHelper.BuildMqttCommand(100, null, HslProtocol.PackStringArrayToByte(data)).Content);
				bool flag3 = !operateResult2.IsSuccess;
				if (flag3)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult<byte, byte[]> operateResult3 = this.ReceiveMqttMessage(socket, 60000, null);
					bool flag4 = !operateResult3.IsSuccess;
					if (flag4)
					{
						result = operateResult3;
					}
					else
					{
						bool flag5 = operateResult3.Content1 == 0;
						if (flag5)
						{
							if (socket != null)
							{
								socket.Close();
							}
							result = new OperateResult(Encoding.UTF8.GetString(operateResult3.Content2));
						}
						else
						{
							try
							{
								OperateResult operateResult4 = new OperateResult();
								using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
								{
									operateResult4 = this.SendMqttStream(socket, fileStream, fileInfo.Length, 60000, reportProgress);
								}
								result = operateResult4;
							}
							catch (Exception ex)
							{
								if (socket != null)
								{
									socket.Close();
								}
								result = new OperateResult("SendMqttStream Exception -> " + ex.Message);
							}
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 使用MQTT协议将一个数据流发送到网络上去，需要保存的文件名，可选指定文件描述信息，进度报告<br />
		/// Use the MQTT protocol to send a data stream to the network, the file name that needs to be saved, optional file description information, progress report
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="stream">数据流</param>
		/// <param name="servername">对方接收后保存的文件名</param>
		/// <param name="filetag">文件的描述信息</param>
		/// <param name="reportProgress">进度报告，第一个参数是已完成的字节数量，第二个参数是总字节数量。</param>
		/// <returns>是否操作成功</returns>
		// Token: 0x06001A28 RID: 6696 RVA: 0x00083728 File Offset: 0x00081928
		protected OperateResult SendMqttFile(Socket socket, Stream stream, string servername, string filetag, Action<long, long> reportProgress = null)
		{
			string[] data = new string[]
			{
				servername,
				stream.Length.ToString(),
				filetag
			};
			OperateResult operateResult = this.Send(socket, MqttHelper.BuildMqttCommand(100, null, HslProtocol.PackStringArrayToByte(data)).Content);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte, byte[]> operateResult2 = this.ReceiveMqttMessage(socket, 60000, null);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content1 == 0;
					if (flag3)
					{
						if (socket != null)
						{
							socket.Close();
						}
						result = new OperateResult(Encoding.UTF8.GetString(operateResult2.Content2));
					}
					else
					{
						try
						{
							result = this.SendMqttStream(socket, stream, stream.Length, 60000, reportProgress);
						}
						catch (Exception ex)
						{
							if (socket != null)
							{
								socket.Close();
							}
							result = new OperateResult("SendMqttStream Exception -> " + ex.Message);
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 使用MQTT协议从网络接收字节数组，然后写入文件或流中，支持进度报告<br />
		/// Use MQTT protocol to receive byte array from the network, and then write it to file or stream, support progress report
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="source">文件名或是流</param>
		/// <param name="reportProgress">进度报告</param>
		/// <returns>是否操作成功，如果成功，携带文件基本信息</returns>
		// Token: 0x06001A29 RID: 6697 RVA: 0x00083838 File Offset: 0x00081A38
		protected OperateResult<FileBaseInfo> ReceiveMqttFile(Socket socket, object source, Action<long, long> reportProgress = null)
		{
			OperateResult<byte, byte[]> operateResult = this.ReceiveMqttMessage(socket, 60000, null);
			bool flag = !operateResult.IsSuccess;
			OperateResult<FileBaseInfo> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<FileBaseInfo>(operateResult);
			}
			else
			{
				bool flag2 = operateResult.Content1 == 0;
				if (flag2)
				{
					if (socket != null)
					{
						socket.Close();
					}
					result = new OperateResult<FileBaseInfo>(Encoding.UTF8.GetString(operateResult.Content2));
				}
				else
				{
					FileBaseInfo fileBaseInfo = new FileBaseInfo();
					string[] array = HslProtocol.UnPackStringArrayFromByte(operateResult.Content2);
					fileBaseInfo.Name = array[0];
					fileBaseInfo.Size = long.Parse(array[1]);
					fileBaseInfo.Tag = array[2];
					this.Send(socket, MqttHelper.BuildMqttCommand(100, null, null).Content);
					try
					{
						OperateResult operateResult2 = null;
						string text = source as string;
						bool flag3 = text != null;
						if (flag3)
						{
							using (FileStream fileStream = new FileStream(text, FileMode.Create, FileAccess.Write))
							{
								operateResult2 = this.ReceiveMqttStream(socket, fileStream, fileBaseInfo.Size, 60000, reportProgress);
							}
							bool flag4 = !operateResult2.IsSuccess;
							if (flag4)
							{
								bool flag5 = File.Exists(text);
								if (flag5)
								{
									File.Delete(text);
								}
								return OperateResult.CreateFailedResult<FileBaseInfo>(operateResult2);
							}
						}
						else
						{
							Stream stream = source as Stream;
							bool flag6 = stream != null;
							if (!flag6)
							{
								throw new Exception("Not Supported Type");
							}
							operateResult2 = this.ReceiveMqttStream(socket, stream, fileBaseInfo.Size, 60000, reportProgress);
						}
						result = OperateResult.CreateSuccessResult<FileBaseInfo>(fileBaseInfo);
					}
					catch (Exception ex)
					{
						if (socket != null)
						{
							socket.Close();
						}
						result = new OperateResult<FileBaseInfo>(ex.Message);
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveMqttRemainingLength(System.Net.Sockets.Socket)" />
		// Token: 0x06001A2A RID: 6698 RVA: 0x000839F0 File Offset: 0x00081BF0
		[DebuggerStepThrough]
		private Task<OperateResult<int>> ReceiveMqttRemainingLengthAsync(Socket socket)
		{
			return Task.Run(() =>ReceiveMqttRemainingLength(socket));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveMqttMessage(System.Net.Sockets.Socket,System.Int32,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A2B RID: 6699 RVA: 0x00083A3C File Offset: 0x00081C3C
		[DebuggerStepThrough]
		protected Task<OperateResult<byte, byte[]>> ReceiveMqttMessageAsync(Socket socket, int timeOut, Action<long, long> reportProgress = null)
		{
			return Task.Run(()=>ReceiveMqttMessage(socket, timeOut, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveMqttStream(System.Net.Sockets.Socket,System.IO.Stream,System.Int64,System.Int32,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A2C RID: 6700 RVA: 0x00083A98 File Offset: 0x00081C98
		[DebuggerStepThrough]
		protected Task<OperateResult> ReceiveMqttStreamAsync(Socket socket, Stream stream, long fileSize, int timeOut, Action<long, long> reportProgress = null)
		{
			return Task.Run(()=>ReceiveMqttStream(socket, stream, fileSize, timeOut, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendMqttStream(System.Net.Sockets.Socket,System.IO.Stream,System.Int64,System.Int32,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A2D RID: 6701 RVA: 0x00083B04 File Offset: 0x00081D04
		[DebuggerStepThrough]
		protected Task<OperateResult> SendMqttStreamAsync(Socket socket, Stream stream, long fileSize, int timeOut, Action<long, long> reportProgress = null)
		{
			return Task.Run(()=>SendMqttStream(socket, stream, fileSize, timeOut, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendMqttFile(System.Net.Sockets.Socket,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A2E RID: 6702 RVA: 0x00083B70 File Offset: 0x00081D70
		[DebuggerStepThrough]
		protected Task<OperateResult> SendMqttFileAsync(Socket socket, string filename, string servername, string filetag, Action<long, long> reportProgress = null)
		{
			return Task.Run(()=>SendMqttFile(socket, filename, servername,  filetag, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.SendMqttFile(System.Net.Sockets.Socket,System.IO.Stream,System.String,System.String,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A2F RID: 6703 RVA: 0x00083BDC File Offset: 0x00081DDC
		[DebuggerStepThrough]
		protected Task<OperateResult> SendMqttFileAsync(Socket socket, Stream stream, string servername, string filetag, Action<long, long> reportProgress = null)
		{
			return Task.Run(() => SendMqttFile(socket, stream, servername, filetag, reportProgress));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveMqttFile(System.Net.Sockets.Socket,System.Object,System.Action{System.Int64,System.Int64})" />
		// Token: 0x06001A30 RID: 6704 RVA: 0x00083C48 File Offset: 0x00081E48
		[DebuggerStepThrough]
		protected Task<OperateResult<FileBaseInfo>> ReceiveMqttFileAsync(Socket socket, object source, Action<long, long> reportProgress = null)
		{
			return Task.Run(()=>ReceiveMqttFile(socket, source, reportProgress));
		}

		/// <summary>
		/// 接收一行基于redis协议的字符串的信息，需要指定固定的长度<br />
		/// Receive a line of information based on the redis protocol string, you need to specify a fixed length
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <param name="length">字符串的长度</param>
		/// <returns>带有结果对象的数据信息</returns>
		// Token: 0x06001A31 RID: 6705 RVA: 0x00083CA4 File Offset: 0x00081EA4
		protected OperateResult<byte[]> ReceiveRedisCommandString(Socket socket, int length)
		{
			List<byte> list = new List<byte>();
			OperateResult<byte[]> operateResult = this.Receive(socket, length, 60000, null);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				list.AddRange(operateResult.Content);
				OperateResult<byte[]> operateResult2 = this.ReceiveCommandLineFromSocket(socket, 10, int.MaxValue);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					list.AddRange(operateResult2.Content);
					result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
				}
			}
			return result;
		}

		/// <summary>
		/// 从网络接收一条完整的redis报文的消息<br />
		/// Receive a complete redis message from the network
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <returns>接收的结果对象</returns>
		// Token: 0x06001A32 RID: 6706 RVA: 0x00083D28 File Offset: 0x00081F28
		protected OperateResult<byte[]> ReceiveRedisCommand(Socket socket)
		{
			List<byte> list = new List<byte>();
			OperateResult<byte[]> operateResult = this.ReceiveCommandLineFromSocket(socket, 10, int.MaxValue);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				list.AddRange(operateResult.Content);
				bool flag2 = operateResult.Content[0] == 43 || operateResult.Content[0] == 45 || operateResult.Content[0] == 58;
				if (flag2)
				{
					result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
				}
				else
				{
					bool flag3 = operateResult.Content[0] == 36;
					if (flag3)
					{
						OperateResult<int> numberFromCommandLine = RedisHelper.GetNumberFromCommandLine(operateResult.Content);
						bool flag4 = !numberFromCommandLine.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<byte[]>(numberFromCommandLine);
						}
						else
						{
							bool flag5 = numberFromCommandLine.Content < 0;
							if (flag5)
							{
								result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
							}
							else
							{
								OperateResult<byte[]> operateResult2 = this.ReceiveRedisCommandString(socket, numberFromCommandLine.Content);
								bool flag6 = !operateResult2.IsSuccess;
								if (flag6)
								{
									result = operateResult2;
								}
								else
								{
									list.AddRange(operateResult2.Content);
									result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
								}
							}
						}
					}
					else
					{
						bool flag7 = operateResult.Content[0] == 42;
						if (flag7)
						{
							OperateResult<int> numberFromCommandLine2 = RedisHelper.GetNumberFromCommandLine(operateResult.Content);
							bool flag8 = !numberFromCommandLine2.IsSuccess;
							if (flag8)
							{
								result = OperateResult.CreateFailedResult<byte[]>(numberFromCommandLine2);
							}
							else
							{
								for (int i = 0; i < numberFromCommandLine2.Content; i++)
								{
									OperateResult<byte[]> operateResult3 = this.ReceiveRedisCommand(socket);
									bool flag9 = !operateResult3.IsSuccess;
									if (flag9)
									{
										return operateResult3;
									}
									list.AddRange(operateResult3.Content);
								}
								result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
							}
						}
						else
						{
							result = new OperateResult<byte[]>("Not Supported HeadCode: " + operateResult.Content[0].ToString());
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveRedisCommandString(System.Net.Sockets.Socket,System.Int32)" />
		// Token: 0x06001A33 RID: 6707 RVA: 0x00083F10 File Offset: 0x00082110
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[]>> ReceiveRedisCommandStringAsync(Socket socket, int length)
		{
			return Task.Run(() =>ReceiveRedisCommandString(socket, length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveRedisCommand(System.Net.Sockets.Socket)" />
		// Token: 0x06001A34 RID: 6708 RVA: 0x00083F64 File Offset: 0x00082164
		[DebuggerStepThrough]
		protected Task<OperateResult<byte[]>> ReceiveRedisCommandAsync(Socket socket)
		{
			return Task.Run(() => ReceiveRedisCommand(socket));
		}

		/// <summary>
		/// 接收一条hsl协议的数据信息，自动解析，解压，解码操作，获取最后的实际的数据，接收结果依次为暗号，用户码，负载数据<br />
		/// Receive a piece of hsl protocol data information, automatically parse, decompress, and decode operations to obtain the last actual data. 
		/// The result is a opCode, user code, and payload data in order.
		/// </summary>
		/// <param name="socket">网络套接字</param>
		/// <returns>接收结果，依次为暗号，用户码，负载数据</returns>
		// Token: 0x06001A35 RID: 6709 RVA: 0x00083FB0 File Offset: 0x000821B0
		protected OperateResult<int, int, byte[]> ReceiveHslMessage(Socket socket)
		{
			OperateResult<byte[]> operateResult = this.Receive(socket, 32, 10000, null);
			bool flag = !operateResult.IsSuccess;
			OperateResult<int, int, byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<int, int, byte[]>(operateResult);
			}
			else
			{
				int length = BitConverter.ToInt32(operateResult.Content, operateResult.Content.Length - 4);
				OperateResult<byte[]> operateResult2 = this.Receive(socket, length, 60000, null);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<int, int, byte[]>(operateResult2);
				}
				else
				{
					byte[] value = HslProtocol.CommandAnalysis(operateResult.Content, operateResult2.Content);
					int value2 = BitConverter.ToInt32(operateResult.Content, 0);
					int value3 = BitConverter.ToInt32(operateResult.Content, 4);
					result = OperateResult.CreateSuccessResult<int, int, byte[]>(value2, value3, value);
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.NetworkBase.ReceiveHslMessage(System.Net.Sockets.Socket)" />
		// Token: 0x06001A36 RID: 6710 RVA: 0x00084064 File Offset: 0x00082264
		[DebuggerStepThrough]
		protected Task<OperateResult<int, int, byte[]>> ReceiveHslMessageAsync(Socket socket)
		{
			return Task.Run(()=>ReceiveHslMessage(socket));
		}

		/// <summary>
		/// 删除文件的操作<br />
		/// Delete file operation
		/// </summary>
		/// <param name="filename">完整的真实的文件路径</param>
		/// <returns>是否删除成功</returns>
		// Token: 0x06001A37 RID: 6711 RVA: 0x000840B0 File Offset: 0x000822B0
		protected bool DeleteFileByName(string filename)
		{
			bool result;
			try
			{
				bool flag = !File.Exists(filename);
				if (flag)
				{
					result = true;
				}
				else
				{
					File.Delete(filename);
					result = true;
				}
			}
			catch (Exception ex)
			{
				ILogNet logNet = this.LogNet;
				if (logNet != null)
				{
					logNet.WriteException(this.ToString(), "delete file failed:" + filename, ex);
				}
				result = false;
			}
			return result;
		}

		/// <summary>
		/// 预处理文件夹的名称，除去文件夹名称最后一个'\'或'/'，如果有的话<br />
		/// Preprocess the name of the folder, removing the last '\' or '/' in the folder name
		/// </summary>
		/// <param name="folder">文件夹名称</param>
		/// <returns>返回处理之后的名称</returns>
		// Token: 0x06001A38 RID: 6712 RVA: 0x00084118 File Offset: 0x00082318
		protected string PreprocessFolderName(string folder)
		{
			bool flag = folder.EndsWith("\\") || folder.EndsWith("/");
			string result;
			if (flag)
			{
				result = folder.Substring(0, folder.Length - 1);
			}
			else
			{
				result = folder;
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06001A39 RID: 6713 RVA: 0x0008415C File Offset: 0x0008235C
		public override string ToString()
		{
			return "NetworkBase";
		}

		/// <summary>
		/// 通过主机名或是IP地址信息，获取到真实的IP地址信息<br />
		/// Obtain the real IP address information through the host name or IP address information
		/// </summary>
		/// <param name="hostName">主机名或是IP地址</param>
		/// <returns>IP地址信息</returns>
		// Token: 0x06001A3A RID: 6714 RVA: 0x00084164 File Offset: 0x00082364
		public static string GetIpAddressHostName(string hostName)
		{
			IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
			IPAddress ipaddress = hostEntry.AddressList[0];
			return ipaddress.ToString();
		}

		/// <summary>
		/// 对客户端而言是的通讯用的套接字，对服务器来说是用于侦听的套接字<br />
		/// A communication socket for the client, or a listening socket for the server
		/// </summary>
		// Token: 0x040005DF RID: 1503
		protected Socket CoreSocket = null;

		/// <summary>
		/// 文件传输的时候的缓存大小，直接影响传输的速度，值越大，传输速度越快，越占内存，默认为100K大小<br />
		/// The size of the cache during file transfer directly affects the speed of the transfer. The larger the value, the faster the transfer speed and the more memory it takes. The default size is 100K.
		/// </summary>
		// Token: 0x040005E0 RID: 1504
		protected int fileCacheSize = 102400;

		// Token: 0x040005E1 RID: 1505
		private int connectErrorCount = 0;
	}
}
